package com.fp.m7.client.widget;

import com.fp.m7.shared.Constants;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.VerticalPanel;

/**
 * Simply a multiline textbox with submit / clear buttons.
 * 
 * @author 7
 */
public class NewCommentWidget extends Composite {

    protected Image imgProfile;
    protected TextArea txtrContents;
    protected Button btnSubmit;
    protected Button btnClear;

    public NewCommentWidget() {
        DockPanel dockPanel = new DockPanel();
        initWidget(dockPanel);
        dockPanel.setHeight("100px");

        imgProfile = new Image(Constants.DEFAULT_AVATAR_URL);
        dockPanel.add(imgProfile, DockPanel.WEST);
        imgProfile.setSize("100px", "100px");

        txtrContents = new TextArea();
        txtrContents.setVisibleLines(5);
        txtrContents.addStyleName("notResizable");
        dockPanel.add(txtrContents, DockPanel.CENTER);
        txtrContents.setSize("253px", "94px");

        VerticalPanel verticalPanel = new VerticalPanel();
        dockPanel.add(verticalPanel, DockPanel.EAST);

        btnSubmit = new Button();
        verticalPanel.add(btnSubmit);
        btnSubmit.setStyleName("buttonSubmit");

        btnClear = new Button();
        verticalPanel.add(btnClear);
        btnClear.setStyleName("buttonClear");
        btnClear.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent arg0) {
                clear();
            }
        });
    }

    public void setContents(String avatarUrl) {
        imgProfile.setUrl(avatarUrl == null ? Constants.DEFAULT_AVATAR_URL : avatarUrl);
    }

    public Image getProfileButton() {
        return imgProfile;
    }

    public Button getSubmitButton() {
        return btnSubmit;
    }

    public TextArea getContents() {
        return txtrContents;
    }

    public void clear() {
        txtrContents.setText("");
    }

}
